0

I'm having trouble with this script recognizing my variable as a variable. The important part of the script is as follows:

    var content = 'imagereims';
    var ms = content.substring(5);
    $.get("../msimages/image.php", {ms: 'ms', pid: '<?php echo "$pid" ?>'}
    );

I want the script to recognize the variable ms as reims, but when the page displays it doesn't recognize the content of the variable. It just repeats ms. I've tried writing the variable without single quotes and with double quotes. I get the same result.

Any suggestions. Thanks

3 Answers 3

5

You'll want to leave off the quotes on 'ms'. Try this:

var content = 'imagesreims'
var ms = content.substring(4);
$.get("../msimages/image.php", {ms: ms, pid: '<?php echo "$pid" ?>'});

'ms' is saying use this string literal as the value.

You'll also want a different substring. Try content.substring(6). content.substring(4) will yield 'esreims'.

As mentioned in another answer, you missed the ); at the end, which I've included in my answer.

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

2 Comments

Well that was my initial thought; but no dice. Maybe I'm doing something wrong with the substring and the variable's empty.
The substring looks correct, but it won't give you what you are expecting. Like I mentioned, use a different substring. The code I gave seems to work (assuming your PHP code works correctly).
1

Here's what you would do:

var content = 'imagesreims'
var ms = content.substring(6);
$.get("../msimages/image.php", {ms: ms, pid: '<?php echo "$pid" ?>'}

Note two things:

  1. use ms as the variable, rather than the literal 'ms'
  2. correct index 4 to 6, if you want reims

1 Comment

Perfect -- those were my two problems. Thanks.
1

Current your line:

var ms = content.substring(4); 

is assigning ms the value esreims. See documentation here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/substring

All of these answers have pointed out errors in the code. You'll want to draw from them all.

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.