HTML variable and text value transfer to PHP/javascript? -


so have in html:

    <p><br><form name="edit" method="post">         <div><select name="edi" id ="edi" >         <option selected="selected">select</option>         <option value="1.php">apple</option>         <option value="1.php">bannana</option>         <option value="2.php">carrot</option>         </select>             <input onclick="return edit();" type="submit" value="edit"/></div>     </form> 

here corresponding javascript:

function edit(){     if(document.forms['edit'].edi.value == "select")         {             alert("please select edit field");             return false;         }     else     {         window.open(edi.options[edi.selectedindex].value);         return true;     } } 

here problem. can see both option apple, , bannana open same php page. want that. want variable in php can store apple/bannana depending chosen in dropdown. tried in php , did not work.

 $table = $_post['edi']; 

i know can create different php page apple(1.php) , bannana(3.php). in program creating page duplicated code. (apple , bannana decide table store in). also, might adding more options in future, dont want keep copying code.

what came putting variable in javascript, tranfering php not possible. decided creating layer rather creating copied pages. (1 selected-shows apple, bananna) (2 selected-shows carrot). can this.

but efficient way of doing this?

you can use php's $_get array access url parameters.

for example:

<option value="1.php?table=apple">apple</option> <option value="1.php?table=banana">banana</option> 

and php:

$table = $_get['table']; 

if variable missing, can provide default value using php's ternary operator:

$table = isset($_get['table']) ? $_get['table'] : 'apple'; 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -