Categories > TinyButStrong general >

probably simple question...

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Assaf
Date: 2008-11-14
Time: 10:30

probably simple question...

Hi,
I have a $var1 in my php file, a <select> combobox inside a form in my template html file.
I would like to post from the html file the "selectedIndex" of the combobox.
If I use the regular $_POST['...'], I get the value (text) of the selection, although I need the index...
I think it shouldn't be too difficult for you gurus out there...
By: Skrol29
Date: 2008-11-14
Time: 11:59

Re: probably simple question...

Hi,

This is not about TBS. A form can only pass the value of a selected item in a combobox. If you need the index, and if this index must be diffrent from the value, then you have to het it using Javascript and save it into a hidden HTML field.
By: TomH
Date: 2008-11-14
Time: 16:04

Re: probably simple question...

It's easier for everyone to undestand you and to help if you post your PHP and HTML template code ;)

This example
<?php
$show = print_r($_POST, true);
echo<<<EOP
<pre>
Show Post $show
</pre>
EOP;
?>
<hr>
<form action="" method="POST">
<select name="select1">
<option value="1" label="list">AAA</option><br>
<option value="2" label="list">BBB</option><br>
<option value="3" label="list">CCC</option><br>
</select><br>
<input type="submit" />
</form>

is executed in TBS like this
<select name="select1">
<option value="[blk.key;block=option]" label="list">[bl;k.text]</option>
<br>
</select>
By: TomH
Date: 2008-11-14
Time: 16:07

Re: probably simple question...

Sorry for the typo...
Should be
<select name="select1">
<option value="[blk.key;block=option]" label="list">[blk.text]</option>
<br>
</select>
By: Assaf
Date: 2008-11-15
Time: 00:33

Re: probably simple question...

Thanks for your help guys,
I'll try to be clearer:
I have a <select> in my html. I can do, for example :
<code>
onchange="alert(document.getObjectByID('selID').selectedIndex)"
</code>
in it's attribute, and see the selected index.
my question was, how do I set variable (defined in the php file) to hold this data ?
something like
<code>[var.theIndex] = <script>document.getObjectByID('selID').selectedIndex</script></code>
By: kle_py
Date: 2008-11-17
Time: 02:14

Re: probably simple question...

The problem is not really clear to me,
but maybe You mean something like:

<select name="select1" onchange="alert(document.getObjectByID('[var.variablename]').selectedIndex)">
<option value="[blk.key;block=option]" label="list">[blk.text]</option>
</select>
or simply something like:

<select name="[var.selectname]" onchange="alert(selectedIndex)">
...
?
I hope my comment helps a little
By: Assaf
Date: 2008-11-17
Time: 02:19

Re: probably simple question...

alright, this far I managed to go...
but I don't want to use ALERT - I want to get this value injected into one of my vars on the php page
thanks...
By: ege
Date: 2008-11-18
Time: 01:29

Re: probably simple question...

Hi,

You simply can't get it's value injected into a php variable unless you comunicate with the server. The html file is on the client's browser, that's why alert, as a javascript command, works. If you need to onchange event to do something on server side without posting the form, you have to write js to request a page from the server either by using location.href="..." or through some ajax communication.

As a side note, if you are not using a customized function that extends document object or a javascript library that does that, document.getObjectById will not work on most (if any) browsers. The correct code should be alert(document.getElementById('selId').value), or as an inline js simply onchange='alert(this.value)'.
By: Assaf
Date: 2008-11-18
Time: 01:55

Re: probably simple question...

that's the logic I was aiming...
cheers, mate
thanks