Jump to content


Photo

onChange not working??


  • Please log in to reply
9 replies to this topic

#1 AdamPGT

AdamPGT
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 07 April 2006 - 05:41 PM

The form fields are being generated via JS, but for some reason when I select the third option, nothing happens.

Here's the code:

<form name="form" method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<table align="center">
    <tr>
        <td><select name="make" style="width:160px;"></select></td>
    </tr>
    <tr>
        <td><select name="model" style="width:160px;"></select></td>
    </tr>
    <tr>
        <td><select name="year" style="width:160px;" onChange="this.form.submit();"></select></td>
    </tr>
    <tr>
        <td> </td>
    </tr>
</table>
</form>

Thanks for any help!

Adam

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 April 2006 - 07:05 PM

Your code wont work as there is nothing to select! You'll want to use the <option></option> tag so the user can select an option from the pull down menu. Heres an example:
<form name="form" method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<select name="year" style="width:160px;" onChange="this.form.submit();">
  <option value="2001">2001</option>
  <option value="2002">2002</option>
  <option value="2003">2003</option>
</select>
</form>


#3 AdamPGT

AdamPGT
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 07 April 2006 - 07:17 PM

[!--quoteo(post=362620:date=Apr 7 2006, 01:05 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 7 2006, 01:05 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Your code wont work as there is nothing to select! You'll want to use the <option></option> tag so the user can select an option from the pull down menu. Heres an example:
<form name="form" method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<select name="year" style="width:160px;" onChange="this.form.submit();">
  <option value="2001">2001</option>
  <option value="2002">2002</option>
  <option value="2003">2003</option>
</select>
</form>
[/quote]
The Options are being generated dynamically using PHP/JS.....even after looking at the page source when everything has been created no <option> tags show up.

--Adam

#4 slipperyfish

slipperyfish
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 09 April 2006 - 12:36 AM

do you have a link? - and in tht case the problem does not lie with ur onChange function.

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 09 April 2006 - 12:00 PM

[!--quoteo(post=362628:date=Apr 7 2006, 08:17 PM:name=AdamPGT)--][div class=\'quotetop\']QUOTE(AdamPGT @ Apr 7 2006, 08:17 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
The Options are being generated dynamically using PHP/JS.....even after looking at the page source when everything has been created no <option> tags show up.

--Adam
[/quote]In that case then there is a problem with your PHP or Javascript that creates the <option></option> tags as they are not being generated!

Could you provide a link for the page has a problem so we can see how your Javascript. Also could you tell us how you are generating your <option> tags with pHP/Javascript.


#6 Vorotaev

Vorotaev
  • Members
  • PipPip
  • Member
  • 27 posts
  • LocationCanada

Posted 09 April 2006 - 01:06 PM

[!--quoteo(post=362628:date=Apr 7 2006, 03:47 PM:name=AdamPGT)--][div class=\'quotetop\']QUOTE(AdamPGT @ Apr 7 2006, 03:47 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
The Options are being generated dynamically using PHP/JS.....even after looking at the page source when everything has been created no <option> tags show up.

--Adam
[/quote]
When using Javascript to dynamically produce code, the changes will not be reflected in the source HTML. The source only shows the page as it was when it was first compiled. Just so you know.

#7 AdamPGT

AdamPGT
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 09 April 2006 - 05:41 PM

HOw would you suggest I submit the form with the change of the third select? Here's a link....I have to edit my .htaccess file real quick:

[a href=\"http://www.gforceauto.com/chain.php\" target=\"_blank\"]http://www.gforceauto.com/chain.php[/a]

--Adam

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 10 April 2006 - 10:42 AM

Your form is submitting, but to its self! You will need something like this:
<?php

if(isset($_POST['year']))
{
   echo "Your have chosen: " . $_POST['make'] . " as the make, " . $_POST['model'] . " as the model, and " . $_POST['year'] . "as the year!";
}

?>
If you wish to show what has been submitted.

#9 AdamPGT

AdamPGT
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 10 April 2006 - 01:31 PM

[!--quoteo(post=363255:date=Apr 10 2006, 04:42 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 10 2006, 04:42 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Your form is submitting, but to its self! You will need something like this:
<?php

if(isset($_POST['year']))
{
   echo "Your have chosen: " . $_POST['make'] . " as the make, " . $_POST['model'] . " as the model, and " . $_POST['year'] . "as the year!";
}

?>
If you wish to show what has been submitted.
[/quote]
THis is already in place:

if (isset($_POST['year'])){
    header("Location: index.php?cPath=" . $_POST['make'] . "_" . $_POST['model'] . "_" . $_POST['year']);
    }

Which would send the page to index.php?cPath=xx_xx_xx, however, the form itself is simply not submitting, that's what I need help with. I need to submit this form without using a Submit button, even though using a submit button does work.

--Adam

#10 AdamPGT

AdamPGT
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 18 April 2006 - 02:43 PM

Anyone have any ideas? I noticed the onClick action works, but it's a bit pre-mature and doesn't grab the third variable.

--Adam




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users