简体   繁体   中英

how can i get the value of my input form be a javascript/php variable?

I can't get the value of the very last line of this code to be anything but static. I need it to be hardcoded so when they pull down the menu and select, it takes that value and puts it forth into the action script.

Any help?

<select id="yo5" onChange="asdf90()"><option>// Let the Page Refresh for each Pick Please!</option>
    <option id="yo4" value="<?php echo $test1 ?>"><?php echo $test1 ?></option>
    <option value="<?php echo $test2 ?>"><?php echo $test3 ?></option>
    <option><?php echo $test4 ?></option>
    <option><?php echo $test5 ?></option>
    <option><?php echo $test6 ?></option>
    <option><?php echo $test7 ?></option>
    <option><?php echo $test8 ?></option>
    <option><?php echo $test9 ?></option>
    <option><?php echo $test10 ?></option>
</select>

<script type = "text/javascript">
    function asdf90()
    {
        elem = <?php $test1 ?>;
        if(document.getElementById('yo5').value = elem)
        {
            alert('hi');
        }
    }
</script>       


<form method="post" action="<?php echo network_admin_url('site-new.php?action=add-site'); ?>">
<div id="nonexsist4"><input name="blog[domain]" type="hidden" value="" /></div>

Put semi-colons after your echo statements..

<option><?php echo $test9; ?></option>

And use the == operator, not =

if(document.getElementById('yo5').value == elem)

The code had several errors. I quote the correct code:

<select id="yo5" onChange="asdf90()">
    <option id="yo4" value="<?php echo $test1; ?>"><?php echo $test1; ?></option>
    <option value="<?php echo $test2; ?>"><?php echo $test3; ?></option>
    <option><?php echo $test4; ?></option>
    <option><?php echo $test5; ?></option>
    <option><?php echo $test6; ?></option>
    <option><?php echo $test7; ?></option>
    <option><?php echo $test8; ?></option>
    <option><?php echo $test9; ?></option>
    <option><?php echo $test10; ?></option>
</select>
<script type = "text/javascript">
function asdf90()
{
    var elem = "<?php echo $test1; ?>";
    if(document.getElementById('yo5').value == elem)
    {
        alert('hi');
    }
}
</script>

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM