Jump to content

Onchange Event help


loganbest

Recommended Posts

need immediate help with this script. When I change the drop down box to 'Picture' I need the the 'reason2' field to automatically have a value of 'When a real picture gets uploaded'

 

<script type="text/javascript">
<!--
function photo(x)
{
var y=document.getElementByName(x).value
if(document.getElementByName(x).value == "Picture"){
document.getElementByName("reason2").value == "When a real picture gets uploaded";
}
}
//-->
</script>
      <form action="forum.php?step=banuser" method="POST">
        <b><u>Ban Player</u></b><br /><br />
        <b>ID: <input name="id" value="' . $id .'" /> Reason:
        <select name="reason" OnChange="photo(this.name)">
          <option value="Spamming">Spamming</option>
          <option value="Picture" OnClick="document.getElementByName(\'reason2\').value=\'When Real Photo is Uploaded\'">Picture</option>
          <option value="Excessive Linking to Other Sites">Excessive Linking to Other Sites</option>
          <option value="Racism">Racism</option>
          <option value="Foul Language">Foul Language</option>
          <option value="Disrespect">Disrespect</option>
        </select>
        Unban: <input type="text" name="reason2" value="MM/DD/YY" /></b>
        <input type="submit" name="submit" value="Ban!">
      </form>

Link to comment
https://forums.phpfreaks.com/topic/68150-onchange-event-help/
Share on other sites

Try this out

<script language="javascript" type="text/javascript">
function chan(x)
{
if(x.value == "Picture")
{
	alert("When Real Photo is Uploaded");
}
}
</script>

<form action="forum.php?step=banuser" method="POST">
        <b><u>Ban Player</u></b><br /><br />
        <b>ID: <input name="id" value="" /> Reason:
        <select name="reason" onchange="chan(this.options[this.selectedIndex])">
          <option value="Spamming">Spamming</option>
          <option value="Picture">Picture</option>
          <option value="Excessives Linking to Other Sites">Excessive Linking to Other Sites</option>
          <option value="Racism">Racism</option>
          <option value="Foul Language">Foul Language</option>
          <option value="Disrespect">Disrespect</option>
        </select>
        Unban: <input type="text" name="reason2" value="MM/DD/YY" /></b>
        <input type="submit" name="submit" value="Ban!">
      </form>

Link to comment
https://forums.phpfreaks.com/topic/68150-onchange-event-help/#findComment-343000
Share on other sites

Then you will have to give an id to your reason2 field

<input type="text" name="reason2" id="reason2" value="MM/DD/YY" />

 

And modify the code alert into this:

if(....){
     document.getElementById("reason2").value = "When Real Photo is Uploaded";
}

Link to comment
https://forums.phpfreaks.com/topic/68150-onchange-event-help/#findComment-349013
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.