Problems Generating Javascript String Variables With Php..
Feb 14, 2005
i'm trying to create some javascript string variables using php. i'm running into a problem because some of the variables span multiple lines and this is causing a problem. here is a sample of what i'm trying to do:
var thetext1=new Array()
thetext1[0]="info for #1 goes here"
thetext1[1]="info for #2 goes here"
thetext1[2]="info for #3 goes here"
etc.... the array values are output from a mysql db using php and used for a script i have on my page.
the problem is some of my strings span multiple lines and end up making it look like:
thetext1[36]= "this is an example
of how some stuff spans
multiple lines"
Using the javascript console in firefox i see the problem is: "Error: unterminated string literal." I believe it is because the string I am trying to input is spanning multiple lines. any idea on how to fix this?
i'm using php/mysql to create these javascript variables so i have access to their functions. i tried doing this:
str_replace( "
", '', $row['text']);
to replace the newlines with nothing but they're still there.
any ideas on how to get around this?
View 3 Replies
ADVERTISEMENT
Sep 4, 2006
The URL is similar to:
https://url.com/form.htm?string=p,val1*l,val2*m,val3*t,val4*d,val5
Within the form, I have the following statement:
<input type="hidden" name="string">With this statement, string should take the value "p,val1*l,val2*m,val3*t,val4*d,val5"
I'm having a problem with the following script:
View 1 Replies
View Related
Jul 22, 2011
I am trying to generate javascript variables. It looks right in the source, but causes a problem. Can someone have a look and tell me why. I have a php script that is pulling out a load of map icons from a database: [URL]
View 2 Replies
View Related
Apr 1, 2009
I have a string that I want to de-construct into several variables. I know I can use Indexof and Slice to do this but was wondering if there is something similar to Indexof that will give me every position of the separator. I know that the separator will always occur a set number of times in the string.
View 3 Replies
View Related
Jul 23, 2010
i'm trying to concatenate to a string 2 variables that i'm adding together but i'm getting Nan as the result
what am i doing wrong?
str_amount=parseInt(document.getElementById('amount').value);
strfeeamount=parseInt(document.getElementById('feeamount').value);
urltoajax=urltoajax + '&amount=' +str_amount +strfeeamount
View 6 Replies
View Related
Jul 23, 2005
I have a PHP page generating a list of items. I've made it so that
each one has a radiobutton with a unique value. You can click on the
radiobutton and it will change the value of a text field to the value
of the radiobutton--all that works fine!
Now, I need to also have it populate a textfield with the value of a
textfield in the row that's selected.
I can make unique field names, no problem. I think my problem is
getting the javascript written so that it recognizes the variable.
Well, see below. As it's written below, the textfield "itemqty" always
has the value "NaN" (wherever THAT comes from) no matter which
radiobutton I select.
View 1 Replies
View Related
Sep 20, 2007
I'm working on a rather complex booking system for building European
trips, in a combination of SQL/VBScript/Javascript. There are tons of
query string variables that get passed back and forth between the
pages, and in almost every case, I can set 'em up fine, provided the
variables are in the link.
The page the *holds* the booking information, though, is problematic.
An example trip might include two European cities or towns with a week
in each in an apartment or cottage that the user selects from a dozen
or properties for each region.
All the information is on one page (all the dozen or so properties for
each weeks, available dates for the trip and for each , max occupancy
per property, pricing per property and per number of passengers,
etc...everything necessary to actually book the trip). If the user
changes party size or chooses a date, properties are hidden or shown
depending on max occupancy and/or availability.
So, a user sets their date and party size (or maybe just the party
size, or maybe has just cleared everything out to start over...) then
wants to view available properties so they can find one they like. The
current pax/date/etc. information is not in the query variables,
because the link was built at runtime.
If I build the link in an onclick event, it breaks if someone right
clicks to open a new page or tab.
I hate sites that disable right click menu. I hate sites where, when
you open a new page with a right click, it generates a javascript
error if the URL is created with an onclick event. I hate that using
an onclick to bring up the page means whatever is showing in the
status bar bears no resemblance to the page that is brought up when
you click on the link.
My client isn't worried about the non-javascript people for this use;
those people are referred to a free spiffy catalog, which frankly, is
how most of this client's customers book their trip anyway. I just
want to be able to carry the variables in such a way as to not break
the site if someone right clicks.
Anybody have any suggestions? Is it hopeless?
View 11 Replies
View Related
Aug 21, 2002
I feel like I have been repeating this code lately, so I cleaned it up and am gonna show it here. This function returns an array (with hash names) containing all the get variables.
function parseGetVars() {
var getVars = new Array();
var qString = unescape(top.location.search.substring(1));
var pairs = qString.split(/&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/=/);
getVars[nameVal[0]] = nameVal[1];
}
return getVars;
}A simple page to test this looks like<html>
<head>
<title>Test</title>
<script>
function parseGetVars() {
var getVars = new Array();
var qString = unescape(top.location.search.substring(1));
var pairs = qString.split(/&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/=/);
getVars[nameVal[0]] = nameVal[1];
}
return getVars;
}
</script>
</head>
<body>
<script>
var g = parseGetVars();
for (var i in g)
document.writeln(i+'='+g[i]+'<br>');
</script>
</body>
</html>
View 19 Replies
View Related
Oct 27, 2010
What is stopping my code from displaying the time, date, and greeting from my stored variables?[code]...
I also tried placing paragraph tags, "", and '' ,respectively, inside the parenthesis as well as using '+variable+' instead of " . variable . "
The word "blah" was used to make sure the marquee tag was supported by browsers I have used to test this. So far I have only run into trouble with my document.write(stuff) not being displayed.
View 8 Replies
View Related
May 26, 2009
I want to pass some variables from one page to the other. Question is, why the following won't work?
<script>
var sq1;
function assignVar(value){
[Code].....
The value of sq1 will remain undefined. It is updating actually, but why it stays the same in query string?
View 2 Replies
View Related
May 6, 2006
I have a program written in Javascript and fully functioning which takes a user-selected directory name and then displays all the photos in that directory in a certain format.
I am now wanting to expand the program to allow users to optionally enter their own strings and the program will use all the photos from www.flickr.com which use that string as a tag.
I have a PHP interface to flickr (called PHPflickr) which collects all the relevant photo urls. I now need to get these images back into my Javascript so I can process them using the existing functions (rather than rewrite all my functions in PHP code and have two sets of functions in the program). I found on another thread a means to do this for a date variable:
var jsArray = new Array(
<?php
$length = count($monthDataArray);
for ($i = 0; $i < $length; $i++)
{
echo '"' . addslashes($monthDataArray[$i]) . '"' . (($i < $length - 1) ? ',' : '') . "
";
}
?>
but being completely new to PHP I'm not sure what "addslashes" might be or what formatting will be necessary if I am starting with an array of urls. Code:
View 1 Replies
View Related
Feb 4, 2006
I have the following javascript function: Code:
function updateParent(dvalue, dfield) {
var field = dfield;
window.opener.document.form.field.value = dvalue;
alert("Value: " + dvalue + " Field: " + field);
self.close();}
I'm calling it as so:
<a onClick="javascript: updateParent(30,'image_id');">Update</a>
But I get the following error:
Error: window.opener.document.form.field has no properties
Why is it not picking up that I have defined the variable field as image_id?
View 2 Replies
View Related
Jul 23, 2005
I need to pass a javascript to JSP code but I cannot figure it out.
View 2 Replies
View Related
Jul 23, 2005
Does someone know how can we bring variables from a PHP script to a
Javascript one ?
I have to build a Javascript function that needs variables generated by a
PHP script but i do not know the way to retrieve them into Javascript.
View 5 Replies
View Related
Feb 23, 2006
I was just reviewing some javascript pop up window functions on my website and I descovered something... that I set the exact same variable name twice for both functions... which is bookWindow. I tested this for pages that use both functions and both types of pop windows work no problem. Is there a problem in that I use the same variable name twice? Is this considered bad form? Or maybe it makes not difference at all because the variable only gets used when it is
called upon and then it leave memory.....
View 2 Replies
View Related
Oct 30, 2006
I have some image data in a Javascript variable, and I want to display
it. I have a technique which works in Firefox but not in Internet
Explorer :
<script>
var testImage = <image data as a string>
</script>
<img src="javascript:testImage"></img>
I understand that this should work in Javascript 1.2 and above, which
supports null characters in strings. Does anyone know why this doesn't
work in Internet Explorer?
View 3 Replies
View Related
Jul 20, 2005
can anybody put forward a sensible argument javascript's behaviour of
creating a new global variable whenever I assign to a previously undeclared
variable. I can't beleive this is just for the sake of convenience (surely
we learned this much from basic).
here's my proposal: all "global" (document scope) variables must be declared
by 'var' outside a function block.
failing that, does anyone know any patterns or tricks I can use to make sure
I don't create a new global variable when I accidentally misspell a variable
name?
View 10 Replies
View Related
Jul 20, 2005
Here's the situation. I have a static html page which we want to update
to include some dynamic content. I want a counter that keeps track of
the number of times anyone presses the "add" button, and display that
number. So, that page would look something like:
Number of calls today: 5
Add | Reset
The "5" would increment with every click of the "Add" link. The "Reset"
link would reset the counter to 0.
I have a Perl script that does all of the accounting stuff (opens a file
that contains the number, increments it, resets it, etc). What I don't
know how to do is to get the data from the CGI script to the web page.
I'm imagining that you can use Javascript, but I can't figure it out.
My CGI script can accept three options (add, view, reset). So it you
call it like so [myscript.cgi?action=add], it increments the counter by one.
So, in a nutshell, this is what I want:
1) the web page to display the # of calls upon load.
2) When a user presses the "Add" link, it invokes the CGI script to
handle the accounting stuff, then refresh the page with the new number
of calls.
3) When a user presses the "Reset" link, it resets the counter to 0.
View 6 Replies
View Related
Jan 18, 2007
I was handed a project that, when launched, had some ajax problems--specifically, "Error: uncaught exception: Permission denied to call method XMLHttpRequest.open." That's easy enough to fix--found the call in the .js file that was referencing the development server instead of the live server, and I am aware of Javascript's same-origin policy, which makes good clean sense. Change that call, problem solved.
Unfortunately, it's not solved. I can change the reference from
var url='http://www.devserver.com/function.php?id='+id;
to
var url='http://www.liveserver.org/function.php?id='+id;
but that doesn't solve the issue of if someone comes to the page without the 'www' or to the other domain, whose TLD is a .com instead of .org.
In PHP, I'd simply write the function to dynamically generate the url string, using $_SERVER variables rather than hardcoding the url. But I'm no javascript guy. Any help would be appreciated.
I'd rather not have to put a php redirect in every page to make sure the url is what I want it to be. I'd much rather learn something new about Javascript.
View 3 Replies
View Related
Jul 16, 2006
A while back I was working on learning C++. However after finding out that making API's was too difficult I switched over to HTML and Javascript for a while to get it to do what I want without having to fry my brain on weird code statements.
Well now I've reached the barrier of being able to save data. For a while I've just had it to the point where the code I need is saved in a textarea and I copy and paste it in notepad. Then upon reentering I pull it out of Notepad and paste into the testarea.
Well enough with the bla bla bla. Is there a way I can use the <form method="post"> stuff to pass a variable to a C++ compiled program?
All I need to know is: 1) can I use <form method="post" action="SomeProg.exe"> and 2) what would the name of the posted variable be to use in my C++ code? As you can tell I running client-side so PHP and other server-side languages that WinXP don't support without special installation wont work.
View 2 Replies
View Related
Jul 25, 2001
I am pretty new to Javascript and have only created a few pretty basic scripts, mainly dealing with site navigation and mouseovers. I would like now to redo my private home page using a rather complex configuration of frames. It is my intention to use JavaScript (variables) to control the rather intricate page navigation.
My question is this. I know how to define a variable, increment or otherwise alter it's value and how to change a process path based on the value of a variable. I have done all of this within the SAME page. What I would like to know more about is the referencing and modification of variables in "pages" in other windows within a frameset.
View 2 Replies
View Related
Jan 29, 2007
I have something that runs on a server with no PHP or any of those widgets.
A user submits a form with 6 fields. Clicks "Go". A page appears that displays what he just entered, with a form of his data in hidden fields, and a link with document.form.submit() that takes you to a CGI program. It must be 2 different page loads.
Is displaying what he entered in the form in the next page possible with JavaScript? If so, what are the JS variables that would let me access that data?
View 3 Replies
View Related
Jul 23, 2005
I'm having a problem passing a variable through a URL because the
variable is supposed to hold a URL that has a variable of its own.
Here is an idea of what I'm trying to do:
href="javascript:
newWin('/vcrc/exitvcrc.jhtml&newURL=http://www.something.net/default.asp?sponID=ETC','NowLeaving',駼',
餠', 'no', 'auto','no');"
So, pretty much, the page I'm sending the variable to think there's two
variables (newURL and sponID), but sponID is part of the URL.
View 2 Replies
View Related
Mar 20, 2007
i have the following snippet of javascript:
liChilds[x].onclick = function(){
toggleSubMenu(sub_menu_id, false);
return false;
}
That code happens within a loop, and sub_menu_id has a different value through each iteration of the loop. For example, if it loops 4 times, then there will be 4 onclick functions and sub_menu_id would change for each one. This should happen in theory, but instead, whichever item you click on, sub_menu_id takes the value of its last value in the loop. (4 in this example)
My question is, how do I make the function toggleSubMenu take the value of sub_menu_id at the time the on click function is created (i.e while looping) rather than taking the value of sub_menu_id when it is actually clicked.
View 2 Replies
View Related
Feb 4, 2005
I'm having a problem getting javascript and vbscript to place nicely together. Here is what I want to do:
I'm getting values from my database for different exam types. Here are some sample values:
Exam Type1
Exam Type2
Exam Type3
Here is how I get the values in vbscript: Code:
View 5 Replies
View Related
Aug 10, 2006
Is there any simple way of passing HTML variables from one HTML page to another HTML page without using PHP or messy URL extensions?
View 5 Replies
View Related