1

I'm working on a project, and if I can get this to work it would save me a lot of time. I want to build a url in my javascript function, with the variable as part of the url. (I'm not good at javascript so I can't explain it properly... but I can show what I've got so far). It's more complicated, but it looks something like this:

I have this function (I know it doesn't work :-) ):

function art1(range) {
top.frames['infoframe'].location.href = 'http://url_part_1' + range + 'url_part_2.html';
}

And this in the body of my page:

<a href='some_other_url' onclick='some_other_functions();art1(C15)'   >

So the result should be this url:

http://url_part_1_C15_url_part_2

EDIT: Ok, additional problem: C15 is in another function, namely here:

function changeText(){
var newHTML = "<td class='tas'><a href='_some_link_' target='changer' 
onclick='setVisibility2();art1(C15)'   (...)

1 Answer 1

3

C15 is a variable (which is, presumably, undefined). You want a string literal instead: "C15".

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

5 Comments

Ok, additional problem: the "string literal" is already part of a javascript function, so I can't put C15 between quotes
@user1312390 — Nothing forbids using string literals in functions.
I'm sorry for the trouble, I should have been more clear :-) see the edit in my post for the real problem. I know the code is getting a bit out of hand, but that's the last thing I have to change for it to work.
I'd refactor this so that you weren't trying to write JavaScript embedded in HTML by mashing together strings in JavaScript (since it quickly becomes an unreadable mess of nested escaping). Use proper DOM methods (createElement, appendChild, addEventListener, etc). That said, the problem is not that it is inside a function but that it is inside a string. Use \" to represent a " in a string delimited with " characters.
I would have (learned and ) used php if I knew how complicated the script would become, but the '\"' -thing worked, it's finished, thanks!

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.