Hi,

I have a form with various elements such as ids, location. I need to pass these values to a php file through a javascript function. Right now I am able to pass only ids.
The Form

<form action="display.php">
    <label>Your ID</label>
        <input type="text" id="ids" name="ids" value="">

    <label>Location</label>
        <select name="location" id="location">
            <option>City 1</option>
            <option>City 2</option>
            <option>City 3</option>
            <option>City 4</option>

    <label>Interest</label>
        <input type="checkbox" name="interest[]" value="Friends" />
        <input type="checkbox" name="interest[]" value="Books" />
        <input type="checkbox" name="interest[]" value="Music" />
        <input type="checkbox" name="interest[]" value="Debates" />

</form>

I am passing the values to the php files through javascript

function passvalues(url, boxid){
            var A = document.getElementById('ids').value; 
            url = url + "?ids=" + A;
            .......
            ........}

PHP File

    $ids=$_GET['ids'];

        echo $ids;
        echo "<br>";

How should I pass 'location' and 'Interest' values also to the php file?

I tried this :-

var B = document.getElementById('location').value; 
                url = url + "?ids=" + A;
                url = url + "?location=" + B;

if 12345 is the id this returns
12345?location=City1

just post your whole form to the php page
(add a submit button to your form and add method="post" to your form tag)

and then get the values from $_POST

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.