tags:

views:

194

answers:

4

``hi,

using whizzywig wysiwyg editor y found that having enter code here makeWhizzyWig("edited", "all"); is ok

but running

<script>
function doit(){
      makeWhizzyWig("edited", "all");
}
</script>

doit()

it breaks....

any suggestion about this difference? also i will appreciate some kind of explanation about this

thanks in advance makerjoe

-------------------------------------------------------------------------------------------

as per your request 

this works ok

<head>
<script type="text/javascript" src="/makerjoe/js/whizzywig.js"></script>
</head>

<body>
<form name="Whizzy" action="whizzed.php" method="post" onsubmit="syncTextarea();">
<textarea name="edited" id="edited" rows="15" cols="70" style="width:99%; height:500px;"> 
</textarea>
<input type="submit" name="submit" value="Submit" title=" Displays your page, which you can Save from the File menu. ">
</form>

<script>
      makeWhizzyWig("edited", "all");
</script>

</body>



------------------------------------------------------------------------------------------

the following does not work!!!

<head>
<script type="text/javascript" src="/makerjoe/js/whizzywig.js"></script>
</head>

<body>
<form name="Whizzy" action="whizzed.php" method="post" onsubmit="syncTextarea();">
<textarea name="edited" id="edited" rows="15" cols="70" style="width:99%; height:500px;"> 
</textarea>
<input type="submit" name="submit" value="Submit" title=" Displays your page, which you can Save from the File menu. ">

</form>
<script>
function doit(){
      makeWhizzyWig("edited", "all");
}
</script>

<a href=javascript:doit()> doit </a>

</body>
A: 

We couldn't see the issue because of your formatting on the question, but after editing it to add code tags for you, I noticed that you are defining your function outside of your <script> tag. The following should work:

<script>
    function doit(){
        makeWhizzyWig("edited", "all");
    }

    doit();
</script>
Mike Trpcic
sorry is my mistakethe doit() is in the bottom of the html page as followsa href="javascript:doit()"> doit </a>thanx
makerjoe
Please edit your original post with your full working code and your full broken code.
Mike Trpcic
A: 

Functions are just a way of grouping statements of code together in a way that makes them easier to call and reuse.

In your example doit() only contains one statement and contains no parameters so the value of it is questionable, you may as well just call makeWhizzyWig directly. However, in most cases functions are a vital part of structuring and organising code.

CurtainDog
so in your opinion both examples are the same, just is a matter of organising the code , but still i dont know why 1. run ok and 2. breaks....
makerjoe
A: 

The code you are showwing it should work. Or at least, the method doit() should get called when you click on the doit link. If you add an alert call at the beginning of the doit method you should see the popup window appear when you click on the link. Do you ?

function doit(){
    alert('should be reached');
    makeWhizzyWig("edited", "all");
}

If you do not see the alert window, what browser are you using ?

Edit

After seeing that it worked, I created a js file:

test.js
function makeTest(param1, param2)
{
    alert("first: " + param1 + " second: " + param2);
}

and modified my html file:

<head> 
<script type="text/javascript" src="test.js"></script> 
</head> 

<body> 


<script> 
function doit()
{
      makeTest("edited", "all");
}
</script> 

<a href=javascript:doit()> doit </a> 

</body> 

This shows that the problem is not in the way you are calling the doit function but that there is a problem inside the makeWhizzyWig() when it is called from a global context. Can't say much more since I do not have the source to makeWhizzyWig but you could try changing

<a href=javascript:doit()> doit </a>

to

<a href="#" onClick="doit()"> doit </a>

and see if it works

MLefrancois
ok i see the alert but the problem is running the makewhizzywig function from the whizzywig.js have you test it ?
makerjoe
Well i do not have the code to your whizzywig so i cannot test it.If you put an alert in the makeWhizzyWig function, do you see it ?
MLefrancois
yes i see it !. but the wysiwyg is not running at all, and yes, the problem is in the makewhizzy() functionanyway i still dont know why the makewhizzy function works with and it breaks called by a function, what is the misterious thing that is happening inside it, and still have doubt on my first question about the difference between html scripting javascript and calling a funtion that does the same thing , are these the same ?
makerjoe
Did you try using the onClick event handler ?The difference between an onClick handler and the javascript: link is the context: onClick executes in the context of the current element (this = the a tag) where when using javascript: executes with a global context (this = window or document, sorry can't remember off the top of my head)
MLefrancois
yes the same thing ..... it doesnt run the makewhizzywig functionand tankx for your time, any way whizzywig is at unverse.net (free) and i would appreciate very much if you can give it a try
makerjoe
A: 

yes i see it !. but the wysiwyg is not running at all, and yes, the problem is in the makewhizzy() function

anyway i still dont know why the makewhizzy function works with and it breaks called by a function, what is the misterious thing that is happening inside it, and still have doubt on my first question about the difference between html scripting javascript and calling a funtion that does the same thing , are these the same ?

makerjoe