Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript
|
BOOK: Beginning JavaScript
This is the forum to discuss the Wrox book Beginning JavaScript by Paul Wilton; ISBN: 9780764544057
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 9th, 2005, 01:09 PM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default JavaScript and Firefox - Urgent Help Needed

Hey there

I'm an ASP coder and I'm building a web portal that involves a lot of user submissions. I made a text formatting toolbar in javascript which was basedon an oreillynet tutorial, but now I'm having problems. It appears that it works fine in IE, but refuses to work at all in Firefox. I've spoken to a few people on my usual ASP forum and they tell me that's because the code is "non standard" and firefox does not support non standard code. Anyway I'm here, basically to beg for help on making my code Javascript 'standard' Can anyone help?

My JavaScript functions are;

Code:
<script>
function format_sel(v) {
  var str = document.selection.createRange().text;
  document.form1.strMessage.focus();
  var sel = document.selection.createRange();
  sel.text = "[" + v + "]" + str + "[/" + v + "]";
  return;
}

function format_sml(v) {
  var str = document.selection.createRange().text;
  document.form1.strMessage.focus();
  var sel = document.selection.createRange();
  sel.text = v;
  return;
}

function insert_link() {
  var str = document.selection.createRange().text;
  document.form1.strMessage.focus();
  var my_link = prompt("Enter URL:","http://");
  if (my_link != null) {
    var sel = document.selection.createRange();
    sel.text = "[link]" + my_link + "[name]" + str + "[/name][/link]";
  }
  return;
}

function mouseover(el) {
  el.className = "raised";
}

function mouseout(el) {
  el.className = "button";
}

function mousedown(el) {
  el.className = "pressed";
}

function mouseup(el) {
  el.className = "raised";
}
</script>
And its called like this (example creates "bold" text)

Code:
<img class="button" 
 onMouseOver="mouseover(this);" 
 onMouseOut="mouseout(this);" 
 onMouseDown="mousedown(this);" 
 onMouseUp="mouseup(this);" 
 onClick="format_sel('b');" 
 src="../images/bold.gif"  
 align="middle" 
 alt="click to make your selection bold">
Any help would be very appreciated.
 
Old December 15th, 2005, 09:34 AM
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Batman,
I am just a novice working my way through 'Beginning Javascript' (and far from being a programmer yet). Having just started on chapter 12 I have tried to use the techniques from this chapter on (part of) your problem. At first I thought I could use the following

[code]
<script type="text/javascript" language="Javascript">

function setHTML(v)
{
    var str = div1.innerHTML;
    str = "<"+v+">"+str+"</"+v+">";
    div1.innerHTML = str;
}
</script>
[code]
<body>
<DIV ID="div1">
    <P>Here is some text.<br>
    The attribute(s) of this text<br>
    can be changed....
    </p>
</DIV>
<input type="button" name="bttn" value="Click to change text to BOLD"
    onclick="return setHTML('B')">
</body>
[code]

This works as expected, but if I tried to use the same concept (i.e. calling setHTML)on a FORM with an TEXTAREA field for user-input, I could not change the attributes of the text. However using the STYLE-object directly is perhaps the way out:

[code]
<script type="text/javascript" language="Javascript">
function setHTML(v,s)
{
    s.style.fontWeight=v;
}
</script>
[code]
<body>
<p>Type in som text....</p>
<br>
<form name="form1">
<textarea id="text1" name="userText1" cols=20 rows=5>
</textarea>
<br>
<input type="button" name="bttn" value="Click to change text to BOLD"
    onclick="return setHTML('Bold',form1.text1)">
</form>
<br>
<DIV ID="div1">
    <P>Here is some text.<br>
    The attribute(s) of this text<br>
    can be changed....
    </p>
</div>
<input type="button" name="bttn" value="Click to change text to BOLD"
    onclick="return setHTML('Bold',div1)">
</body>
[code]

I am not sure if this is what you are looking for, but anyway
SteenH





Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox vs. IE - Javascript problem VerbatimBOT ASP.NET 2.0 Professional 2 September 25th, 2008 03:28 AM
Javascript - Firefox is not supporting lakshmi252002 General .NET 0 April 17th, 2007 12:14 AM
Firefox javascript error akkad Ajax 2 November 27th, 2006 10:57 AM
Toolbar in FireFox - Urgent Help Needed Batman Javascript 1 December 9th, 2005 01:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.