0

I am new to php and trying to get a php curl request variable to be populated from a html drop down form. I want this request to reload the page upon selection. The following code below give this error

select.php:19 Uncaught TypeError: document.getElementById(...).submit is not a function at change (select.php:19) at HTMLSelectElement.onchange (select.php:10)

<html>          
<head>
</head>

<body>

 <form method="post">
 <select id="wipname2" name="wipname2" style='position: relative' onchange="change()">
     <option value="site1.com">site1.com</option>
     <option value="site2.com">site2.com</option>
     <option value="site3.com">site3.com </option>
 </select>
 </form>

 <script>
 function change(){
     document.getElementById("wipname2").submit();
 }
 </script>

<?php

 $curl = curl_init();

curl_setopt_array($curl, array(
  //CURLOPT_URL => 'https://example.com/MagicService/rest/ltmNode?wipNames='.$_GET["wipnames2"],
  CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=".'$_GET["wipnames2"]',
// CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=content.gslb.fmr.com",
//  CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=$value",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Accept: application/json",
    "Cache-Control: no-cache",
    "access-token: df11c69eabb9eab4abaf4bcc6b1e62a26025e830",
    "password: ",
    "username: "
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
        //fwrite($output,$response);
//print_r (explode(" ",$response));
echo $response;

}

?>

</body>
</html>
5
  • 2
    You can change <form method="post"> to <form id="theForm" method="post"> and then change document.getElementById("wipname2").submit(); to document.getElementById("theForm").submit(); Commented Oct 8, 2018 at 15:35
  • Thanks @Hackerman this worked perfectly Commented Oct 8, 2018 at 15:44
  • @Glad to help!! Commented Oct 8, 2018 at 15:45
  • please don't post answers in the comment section. Commented Oct 8, 2018 at 15:47
  • can anyone explain why the url is not working with this at the end '.$_GET["theForm"] Commented Oct 9, 2018 at 23:34

2 Answers 2

1

submit() is a reference to the text input with name="submit" in form.

put <input type="hidden" name="submit" value="submit" /> inside form and then it will work.

reference

Sign up to request clarification or add additional context in comments.

Comments

0

The issue is with this piece of code document.getElementById("wipname2").submit();. wipname is a select control, and it doesn't have a submit event. But you have that control inside a form, so you can make that work with just some minor changes:

  1. You can change <form method="post"> to <form id="theForm" method="post"> in order to add an identifier(id) to your form.
  2. And then change document.getElementById("wipname2").submit(); in your change function, to document.getElementById("theForm").submit(); in order to trigger your form submit event.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.