Variable passing problems

  • Carpdung
  • Newbie
  • Newbie
  • Carpdung
  • Posts: 11

Post 3+ Months Ago

Hello all,

I have a link within an email that is such that:

http://some.url.com/somefile?ticket_number=12345

The purpose for this is so that The "Ticket Number" will be 'autofilled' when the User accesses the form. However, I either get "Undefined" output....or the variablename is populating the field.

Can someone please tell me where I'm going wrong?

Thanks in advance! :( :( :(
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Are you using PHP, ASP, CGI, Perl, JSP, ...?
  • Carpdung
  • Newbie
  • Newbie
  • Carpdung
  • Posts: 11

Post 3+ Months Ago

Hi Leo,

I'm using HTML.

Let me see if I can explain...The email has a link for users such that:

http://some.url.com/somefile.html?ticket_number=123

somefile.html has a form within. With some past help, I placed inside of the 'head' something like:
Code: [ Select ]
<script>
var ticktick = ticket_number;
</script>
  1. <script>
  2. var ticktick = ticket_number;
  3. </script>


Within the 'body', I have something like:
Code: [ Select ]
<tr>
  <td ALIGN="left"><b>Autofill(Ticket Number): </b></td>
  <td><script>document.write(ticktick)</script></td>
</tr>
  1. <tr>
  2.   <td ALIGN="left"><b>Autofill(Ticket Number): </b></td>
  3.   <td><script>document.write(ticktick)</script></td>
  4. </tr>

This yields me and 'Undefined' output in the field.

I tried doing something like:
Code: [ Select ]
<tr>
  <td ALIGN="left"><b>Autofill(Ticket Number): </b></td>
  <td><input value="$ticktick" name="ticket_number"></td>
</tr>
  1. <tr>
  2.   <td ALIGN="left"><b>Autofill(Ticket Number): </b></td>
  3.   <td><input value="$ticktick" name="ticket_number"></td>
  4. </tr>

But this yields the variable name in the field and not the value.

I am open to ANY method as long as it works.

How can I get my HTML code to read the variable from:
http://url.com/somefile.html?ticket_number=123

?

Thanks,
-Carpdung
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Well, variables passed in an HTTP request are intended for server side scripting. Therefore, you won't be able to get them with javascript. I have to encorugate you to use PHP, ASP or any other server side software.

If you can't do that, well, I have found this workarround:

Code: [ Select ]
<SCRIPT>
function parseQueryString (str) {
 str = str ? str : location.search;
 var query = str.charAt(0) == '?' ? str.substring(1) : str;
 var args = new Object();
 if (query) {
  var fields = query.split('&');
  for (var f = 0; f < fields.length; f++) {
   var field = fields[f].split('=');
   args[unescape(field[0].replace(/\+/g, ' '))] = unescape(field[1].replace(/\+/g, ' '));
  }
 }
 return args;
}
</SCRIPT>
...
...
<SCRIPT>
var args = parseQueryString ();

document.write(args['ticket_number']);

</SCRIPT>
  1. <SCRIPT>
  2. function parseQueryString (str) {
  3.  str = str ? str : location.search;
  4.  var query = str.charAt(0) == '?' ? str.substring(1) : str;
  5.  var args = new Object();
  6.  if (query) {
  7.   var fields = query.split('&');
  8.   for (var f = 0; f < fields.length; f++) {
  9.    var field = fields[f].split('=');
  10.    args[unescape(field[0].replace(/\+/g, ' '))] = unescape(field[1].replace(/\+/g, ' '));
  11.   }
  12.  }
  13.  return args;
  14. }
  15. </SCRIPT>
  16. ...
  17. ...
  18. <SCRIPT>
  19. var args = parseQueryString ();
  20. document.write(args['ticket_number']);
  21. </SCRIPT>
  • Carpdung
  • Newbie
  • Newbie
  • Carpdung
  • Posts: 11

Post 3+ Months Ago

Hi Leo,

Both you and Stinger have been quite helpful with me on this issue. Much thanks to both of you! :D

I believe Stinger was telling me the same thing of the importance of using sidesoftware with functions to accomplish my results. Now I understand.

I have self-taught myself HTML, and as you can tell, when some tasks become more sophisticated I have a much more difficult time achieving my results. Is PHP something that I can pickup on my own in short fashion? Training from my company is very hard to come by these days and it appears that PHP, ASP, etc are things that I really need to understand. What would you suggest on how I proceed in learning PHP?

Once again, thank you for your assistance and I'll try the work-around you provided. :)

-Carpdung
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

You are welcome.

Be carreful when thinking about JavaScript (client side) and PHP (server side) as one isn't replacement for the other. PHP isn't a sophisticated JavaScript as a plain isn't a sophisticated car :)

You can check the web for a complete list of differences. I will just mention one:

PHP runs in the server, therefore, end-user is not able to know how nor what it does. End-user isn't able to modify its behavior as he could do with JavaScript. Basically, you CAN'T trust data coming form a JavaScript.

I would recommend you to start with a PHP tutorial. There are hundres in the web. You can check http://www.php.net, the actual PHP official site.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 191 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.