Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am working on a JQuery script that essentially pulls data from a select box based on input and either hides/shows variables based on selection (testing data in currently)

I have the script working as far as JQUERY refreshing and updating the values. My current issue is that I cannot seem to get the variable to pass through for use in other steps.

Here is what I have so far. Now I have a problem passing the variable through to the next step.

This is the JQuery/HTML section:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript"><!--
$(document).ready(function() {
  // When the form is submitted to PHP Call
  $('#crs').submit(function() {
    // Get form data ready for PHP Call
    var Sphone = $('#crs #Sphone').val();
    var Schat = $('#crs #Schat').val();
    var Smeet = $('#crs #Smeet').val();
    var Sremo = $('#crs #Sremo').val();
    var Sport = $('#crs #Sport').val();
    var Smail = $('#crs #Smail').val();
    var Svoic = $('#crs #Svoic').val();
    var Sfax = $('#crs #Sfax').val();


    // put form data in a JSON format that will be sent to the PHP File
    var data_json = {'Sphone':Sphone, 'Schat':Schat, 'Smeet':Smeet, 'Sremo':Sremo, 'Sport':Sport, 'Smail':Smail, 'Svoic':Svoic, 'Sfax':Sfax};

    // Set AJAX method
    // If succeeds, goes to the  next step
    $.ajax({
      type: 'post',
      url: 'script.php',
      data: data_json,
      beforeSend: function() {
        // before send the request, displays a "Loading..." messaj in the element where the server response will be placed
        $('#resp').html('Loading...');
      },
      timeout: 10000,        // sets timeout for the request (10 seconds)
      error: function(xhr, status, error) { alert('Error: '+ xhr.status+ ' - '+ error); },
      success: function(response) { $('#resp').html(response); }
    });

    return false;      // required to not open the page when form is submited
  });
});
--></script>
</head>
<body>
<div id="resp"></div>
<h4>Fill the form:</h4>
<form action="script.php" method="post" id="crs">
Phone Support: <select name="Sphone" id="Sphone">
  <option value="Pen1">Yes</option>
  <option value="">No</option>
   </select><br />

Live Chat Support: <select name="Schat" id="Schat">
  <option value="Pen2">Yes</option>
  <option value="">No</option>
   </select><br />

Live Meeting: <select name="Smeet" id="Smeet">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />
Remote Support: <select name="Sremo" id="Sremo">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />
Ticket By Portal: <select name="Sport" id="Sport">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

Ticket By Email: <select name="Smail" id="Smail">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

Ticket By Voicemail: <select name="Svoic" id="Svoic">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

Ticket By Fax: <select name="Sfax" id="Sfax">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

 <input type="submit" value="submit" />
</form>

This is the PHP section.

if(isset($_POST['Sphone']) && isset($_POST['Schat']) && isset($_POST['Smeet']) && isset($_POST['Sremo']) && isset($_POST['Sport']) && isset($_POST['Smail']) && isset($_POST['Svoic']) && isset($_POST['Sfax'])) {
  $_POST = array_map("strip_tags", $_POST);       // Gets rid of tags in POST Call

  // get data
  $Sphone = $_POST['Sphone'];
  $Schat = $_POST['Schat'];
  $Smeet = $_POST['Smeet'];
  $Sremo = $_POST['Sremo'];
  $Sport = $_POST['Sport'];
  $Smail = $_POST['Smail'];
  $Svoic = $_POST['Svoic'];
  $Sfax = $_POST['Sfax'];

// Define Full Output of variable   
  $arrow ='<textarea name="supportArticle" cols="160" rows="15" wrap="virtual">'.$Sphone.' <br> '.$Schat.' <br> '.$Smeet.' <br> '.$Sremo.' <br> '.$Sport.' <br> '.$Smail.' <br> '.$Svoic.' <br> '.$Sfax.'</textarea>';
   function passVariable($arrow)
    {
    return $arrow or die(mysql_error());
    }
  }
echo $arrow; 

I did have more code above this, but that is just the database connection, etc.

This works fine to change the variables. Right now I have Pen 1, Pen 2, etc... as placeholders (with a break in between).

I want to keep all of this into one file. I tested this with a variable named $arrow and it will not echo this variable (added a DIE error to it also, then removed) - any takers?

share|improve this question
    
WARNING! You're passing unfiltered, unvalidated user input right back out. This can create a cross-site scripting vulnerability, easily allowing malicious users to hijack your site for their own purposes. Please add appropriate validation to user input and filtering on output of user-provided data. –  Charles Dec 16 '12 at 19:04
    
This is a ONE time script. Put on, take off sites. I understand it is very insecure. –  Justin Bevan Dec 16 '12 at 19:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.