Really easy question about forms
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Really easy question about forms
Hi,
Just wondering how you can get a page to respond to selections in a select (drop down) box in a form without even having to click the submit button but still send the form data when the button is eventually clicked?
I basically want the page with the form on it to dislpay different things when certain selections are made.
Thanks
Just wondering how you can get a page to respond to selections in a select (drop down) box in a form without even having to click the submit button but still send the form data when the button is eventually clicked?
I basically want the page with the form on it to dislpay different things when certain selections are made.
Thanks
- SilverMist
- Forum Commoner
- Posts: 65
- Joined: Tue Mar 02, 2004 2:06 pm
- Location: Canada
- Contact:
- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
That's done with javascript.
something like this:
when the user changes the dropdown menu the javascript function update() is called. You have to define the function though.
something like this:
Code: Select all
<script>
function update() {
alert(document.form['test_form'].test.value);
}
<script>
<form name='test_form'>
<select name='test' onchange='update()'>
<option value='test1'>Test 1</option>
<option value='test2'>Test 2</option>
</select>
</form>
Last edited by andre_c on Mon Apr 12, 2004 6:58 pm, edited 1 time in total.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Kind of yeah, but not even as complicated as that.Like when a person goes to country, then canada, and when canada is clicked, a list of provinces appears?
Just to echo a word onto the page. For example, my form is for downloading polyphonic ringtones. But there are several formats available so there is a select box to choose the format.
All I want to do is to echo a word such as "Midi" or "SMAF" somewhere on the page when the selection is chosen.
I'll also be displaying the filesize but if I know how to make the page respond to actions on the form then I'll be able to sort that out anyway.
I used to have a separate page for each format but it was too confusing and a waste of server space so since I have every ringtone available in all formats I figured this method would be easier.
- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
using the code above do:
Edited: changed form['test_form'] to forms['test_form']
Code: Select all
<script>
function update() {
document.getElementById('selection').innerHTML= document.forms['test_form'].test.value;
}
</script>
<span id='selection'>None yet</span>
<form name='test_form'>
<select name='test' onchange='update()'>
<option value='test1'>Test 1</option>
<option value='test2'>Test 2</option>
</select>
</form>
Last edited by andre_c on Mon Apr 12, 2004 7:19 pm, edited 1 time in total.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I just tried that code in a little test page I made but it doesn't seem to work.
It just displays a page with "Not Yet" at the top and then below it is a select box with "Test 1" and "Test 2" but when either of them is selected nothing happens.
Am I just being a dunce or is this code not correct?
Thanks
It just displays a page with "Not Yet" at the top and then below it is a select box with "Test 1" and "Test 2" but when either of them is selected nothing happens.
Am I just being a dunce or is this code not correct?
Thanks
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
The JavaScript idea was working very well until....
I needed to do more than just echo a string onto the page.
I needed to use the php function filesize(); to get a filesize and then somehow get JavaScript to print whatever this value was. It's virtually impossible I think.
Is there no other way of sending information about selections in a select box instantly using some kind of hidden submit in each option tag?
What's happening in other peoples scripts when the page seems to refresh for a moment with new info on the page?
Thanks
I needed to do more than just echo a string onto the page.
I needed to use the php function filesize(); to get a filesize and then somehow get JavaScript to print whatever this value was. It's virtually impossible I think.
Is there no other way of sending information about selections in a select box instantly using some kind of hidden submit in each option tag?
What's happening in other peoples scripts when the page seems to refresh for a moment with new info on the page?
Thanks
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
You could do it all before hand - that is, store filesizes in the DBase and use PHP to build two arrays, one with file name and one with file size. Use your update fxn to find the file name and display the corresponding file size. Its not pretty but it works.
Another option is to add a self redirect into your update and pass the selected file name then you can use php to look it up easily.
Another option is to add a self redirect into your update and pass the selected file name then you can use php to look it up easily.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Can you open php tags and jump into php mode just to echo some string into the script whilst you're inside your <script> tags???
That would solve everything. I dont see why it shouldn't work. I'll have a go..... actually on second thoughts, even if you can do that it may not work since I need if else statements depending upon user input on client side. Hmmmmm
Thanks
That would solve everything. I dont see why it shouldn't work. I'll have a go..... actually on second thoughts, even if you can do that it may not work since I need if else statements depending upon user input on client side. Hmmmmm
Thanks
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I'm just checking it out on a little test page but the JavaScript seems to ignore the php. Here's the way I'm trying it below:
Do I need to escape to php a little differently to the way I'm doing it?
Code: Select all
<script>
function update() {
document.getElementById('selection').innerHTML= <?php echo "Somestring"; ?>;
}
</script>
<span id='selection'>None yet</span>
<form name='test_form'>
<select name='test' onchange='update()'>
<option value='test1'>Test 1</option>
<option value='test2'>Test 2</option>
</select>
</form>