Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Example is here.

I'm moving countries from one select box to another, when I submit the form I want the values in the right text box to be used by php. When I give the right box a name for a php array, like ToLB[] the Javascript fails. How can I handle this so that the submitted values will be used by php processes?

Screen Shot of Web Page

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
136 views
Welcome To Ask or Share your Answers For Others

1 Answer

in forms it's a typical process to use an action and a method. This is declared within the form tag. For example

<form name='phpSend' method='post' action='myActions.php'>

Now when your form is submitted it is instantly 'posted' to the url myActions.php and is automatically declared as a $_POST array.

The names of the inputs become the array keys and the value becomes the value.

A basic method is to do a procedural action. Meaning if you leave the action attribute blank, the action will submit the form to the page you're already on and use if statements to check if the form has been submitted.

if(isset($_POST)&&isset($_POST['someName'])){
    //form submitted!
}

Now, I've never used a multiple select before so you may want to var_dumb() or print_r() your output to double check but my guess is it'll be an Array within the $_POST array.

Submitting with javascript

if(document.getElementByName('phpSend').submit){//or however your checking
    var selected=[];
    for(var e=0;e<document.getElementByTagName('select').options.length;e++){
        if(document.getElementByTagName('select').options[e].selected==true)selected[e]=document.getElementByTagName('select').options[e].value;
    }
//then add the selected array to your preferred method of sending your data to your php document
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...