select box onselect resfresh

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
FireElement
Forum Commoner
Posts: 86
Joined: Wed Oct 17, 2007 6:03 pm

select box onselect resfresh

Post by FireElement »

scottayy | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hey people!

I am looking to figure out how when I select an item on a select box. The page is refreshed and the info in the select box is posted back to the page
E.g

[syntax="html"]<select name="sport">
          <option value="null" selected="selected">-select-</option>
          <option value="rugby" >-select-</option>
          <option value="football" >-select-</option>
</select>
Something like

<select name="sport" onselect="submit">
....[/syntax]

Code: Select all

<?php
$_post['sport'];
?>
Basically am trying to reload page so I can put what is in the select box in a php variable so it can be used in real time. Any help would be amazing! Thanks!!


scottayy | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

What you want to look at is javascript to submit the form.

Code: Select all

<select onchange="document.forms[0].submit();">
Moved to Client Side
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
FireElement
Forum Commoner
Posts: 86
Joined: Wed Oct 17, 2007 6:03 pm

Post by FireElement »

scottayy wrote:What you want to look at is javascript to submit the form.

Code: Select all

<select onchange="document.forms[0].submit();">
Moved to Client Side
woops soz I just posted it using code thinking it would. I will keep it neater from now on.

I know I need to use javasctipt to submit the form, but am pulling sql tables in and I need to store the result in php so I can pull the next sql file in the following select box.

So basically I need to work out how to reload the page onselect of drop down select box and post the result back to the page so I can use the selected data and update the select box below.

Basically making a chained select box. On select of select box one the second select box inputs sql selections available!!
FireElement
Forum Commoner
Posts: 86
Joined: Wed Oct 17, 2007 6:03 pm

Post by FireElement »

FireElement wrote:
scottayy wrote:What you want to look at is javascript to submit the form.

Code: Select all

<select onchange="document.forms[0].submit();">
Moved to Client Side
woops soz I just posted it using code thinking it would. I will keep it neater from now on.

I know I need to use javasctipt to submit the form, but am pulling sql tables in and I need to store the result in php so I can pull the next sql file in the following select box.

So basically I need to work out how to reload the page onselect of drop down select box and post the result back to the page so I can use the selected data and update the select box below.

Basically making a chained select box. On select of select box one the second select box inputs sql selections available!!

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Sample</title>


</head>
<body>
<?php
$poo=$_POST['poo'];
$intel=$_POST['intel'];
$current=$_POST['current'];
$current_location=$_POST['current_location'];

?>


<form id="myForm" method="post" >


<input type="text" name="current" maxLength='255' value="<?php echo $current; ?>"><br>
<input type="text" name="current_location" maxLength='255' value="<?php echo $current_location; ?>">
<br>
<select name="poo" >
<?php
if ($poo==""){
echo "<option value="-select-" selected="selected">-select-</option>";
}else{
echo "<option value="-select-">-select-</option>";
echo "<option value="$poo" selected="selected">$poo</option>";
}
?>
<option value="poo">poo</option>
<option value="poop">poop</option>
<option value="other">Other</option>
</select>
<br>
<select name="intel" onChange="submit()" >
<?php
if ($intel==""){
echo "<option value="-select-" selected="selected">-select-</option>";
}else{
echo "<option value="-select-">-select-</option>";
echo "<option value="$intel" selected="selected">$intel</option>";
}
?>
<option value="Dull">Dull</option>
<option value="Smart">Smart</option>
<option value="Brilliant">Brilliant</option>
<option value="other">Other</option>
</select>
<br>
<?php if ($intel==""){ ?>
<select name="second" disabled="true">
<?php } elseif ($intel=="other"){ ?>
<input type="text" name="current" maxLength='255'>
<?php } else { ?>
<select name="second" >
<?php }
if ($intel!="other"){
  if($intel=="Dull"){
    echo "<option value="Dummy ">Dummy</option>";
    echo "<option value="Dope">Dope</option>";
    echo "</select>";
  }
  elseif($intel=="Smart"){
    echo "<option value="Hmm">Hmm</option>";
    echo "<option value="Middle">Middle</option>";
    echo "</select>";
  }
  elseif($intel=="Brilliant"){

    echo "<option value="Genius">Genius</option>";
    echo "<option value="Geek">Geek</option>";
    echo "</select>";
  }
}
?>

</form>
</body>
</html>
I dont know if anyone was trying to do what I said? But here is some code on what I have so far! If anyone can see a problem with this code please tell me!

I am slighly worried about running this on a big form... because it will post all info with out verification if I dont do it right but what my aim is to post everything back and use the submit button to verify and post all the data again later.... this worries me because am not sure I will be able to do this but if it works out I will post the next code. The reason am doing this is so I can pass sql data in! Guess I have to try get it submiting and verfing now! If anyone thinks this form is dangous or unsecure can they please point out why! Thanks
Post Reply