Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript removes my "/" character ? 2

Status
Not open for further replies.

Splittle

ISP
Jun 21, 2005
26
GB
hello

why is my "/" character being removed from...

onclick="javascript:rtf.scr='main/index.js';"

.. code ?

also how do it fix this.

thanks in advance.
 
<script>
alert('main/index.js')
</script>

works fine...

Known is handfull, Unknown is worldfull
 
what do you mean by "/" is removed ? when ? how ?

Water is not bad as long as it remains outside human body ;-)
 
does that mean i have to write a function just to change one
<script src="main/index.js"> source ?
 
when i click <font onclick="javascript:rtf.src='main/index.js';">change</font>

the status bar shows ... ( localhost/mainindex.js )

without the "/" .
 
use document.write()

<script>
document.write("<script>index.js</script>")
</script>

Known is handfull, Unknown is worldfull
 
i can't use document.write as i am already writing into a
div innerHTML=, and it will rewrite my page, unless i do it
at the time that the page is first loaded, which seems alot
of work just to change the rtf.src .
 
What the status bar show is not really important. what is important is if wether or not rtf object source is changed with the js you gave that you can check with the behavior of the script.


Water is not bad as long as it remains outside human body ;-)
 
maybe Targol, but it doesn't change.
It works fine when i change it by hand

ie edit it to <script src="main/index.js"></script>
or <script src="main/index2.js"></script>

but i want it to change onclick.
 
it should work.

when i use ..

<script id=rtf src="index.js"></script>
<font onclick="javascript:rtf.src='index2.js';">change</font>

it will change, but i need the sub folder "main".
 
what's the aim for that ? I ask it because I'm not sure that changing a script source on the fly should work well. Let me understand : your 2 js files have the same functions within but with differents implementations ?

Water is not bad as long as it remains outside human body ;-)
 
I'm using th js's as a kind of database holding different
information to be entered in a div tag.
 
So, can't U link to the 2 js within your htm and fill each one with a different function that you'll call depending on which button (or font) was pressed ?

Water is not bad as long as it remains outside human body ;-)
 
Probably, i thought i'd ask here as to why the "/" chatacter
was being remaoved first, as it would be alot quicker
to put
Code:
<font onclick="javascript:rtf.src='main/index.js';">change</font>

or

<font onclick="rtf.src='main/index.js';">change</font>

than it would to write a whole new function.

but i guess i'll have to, thanks for your time anyway.
 
well, I can't figure why it's disapearing. A nuts option : did you try to double it ("main//index.js" instead of "main/index.js"). Other hint : try a relative path like "../main/index.js"

Water is not bad as long as it remains outside human body ;-)
 
what browser? what os? are you sure you're using a forward slash and not a backslash? is this in some sort of server-side page like php that may be stripping these characters?

you say "the status bar shows ... ( localhost/mainindex.js )"
what is causing this? nowhere in your code have you shown any calls to setting statusbar text. do you have any other undisclosed functions acting here?

for cross-browser compatibility i suggest using something like so (also the <font> element is deprecated):
Code:
<script [highlight]id="rtf"[/highlight] src="main/index.js"></script>

<span onclick="[highlight]document.getElementById('rtf')[/highlight].src = 'main/index2.js';"></span>

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
when i say the status bar shows ( localhost/mainindex.js )
i just mean i can see it trying to load in the js without
the "/", o/s XP pro, browser firefox.

having said that i've just tryed your code..

<script id="rtf" src="main/index.js"></script>

<font onclick="document.getElementById('rtf').src = 'main/index2.js';"></font>

and it worked ? :-/

not sure why but thanks all the same.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top