0

I have this form

For the star there are 5 images with onclick set to functionstar1, functionstar2 etc... that change the url of the images (there are 2 url star1.png(yellow) and star2.png(white)). This is the script for the control of the stars:

<script>function functionStar1() {
document.getElementById('star1').src = "star1.png";
document.getElementById('star2').src = "star0.png";
document.getElementById('star3').src = "star0.png";
document.getElementById('star4').src = "star0.png";
document.getElementById('star5').src = "star0.png";
}
function functionStar2() {
document.getElementById('star1').src = "star1.png";
document.getElementById('star2').src = "star1.png";
document.getElementById('star3').src = "star0.png";
document.getElementById('star4').src = "star0.png";
document.getElementById('star5').src = "star0.png";
}
function functionStar3() {
document.getElementById('star1').src = "star1.png";
document.getElementById('star2').src = "star1.png";
document.getElementById('star3').src = "star1.png";
document.getElementById('star4').src = "star0.png";
document.getElementById('star5').src = "star0.png";
}
function functionStar4() {
document.getElementById('star1').src = "star1.png";
document.getElementById('star2').src = "star1.png";
document.getElementById('star3').src = "star1.png";
document.getElementById('star4').src = "star1.png";
document.getElementById('star5').src = "star0.png";
}
function functionStar5() {
document.getElementById('star1').src = "star1.png";
document.getElementById('star2').src = "star1.png";
document.getElementById('star3').src = "star1.png";
document.getElementById('star4').src = "star1.png";
document.getElementById('star5').src = "star1.png";
}</script>

I send information using javascript because i need the url of the star using this script:

<script>var password;
var titolo;
var feedback;
var valutazione;
var url;
function open(){
password = document.getElementById("password").value;
titolo = document.getElementById("titolo").value;
feedback = document.getElementById("feedback").value;
if (document.getElementById('star5').src == 'http://www.***.eu/star1.png') {
    valutazione = 'Eccellente';
} else if (document.getElementById('star4').src ==  
'http://www.***.eu/star1.png'){
    valutazione = 'Discreto';
}else if (document.getElementById('star3').src ==     
'http://www.***.eu/star1.png'){
    valutazione = 'Sufficiente';
}else if (document.getElementById('star2').src ==  
'http://www.***.eu/star1.png'){
    valutazione = 'Non sufficiente';
} else {
    valutazione = 'Pessimo';
}
url = 'http://www.***.eu/input.php?password=' + password + '&titolo=' +   
titolo + '&feedback=' + feedback + '&valutazione=' + valutazione;
document.getElementById("buttonhref").href = url;
}
setInterval(open, 10)</script>

The problem is that it sends the <textarea> text without the \n. Is there a way to take the text with \n using javascript or better is there a way to send the url of the star images without javascript?

  • Check this: http://stackoverflow.com/questions/12896504/javascript-save-textarea-value-with-line-breaks – Nikhil Dec 24 '15 at 11:10

1 Answers1

0

If you don't want to use Javascript for sending the data, uou could set a hidden value that gets updated with the amount of stars, and then process that after the form has been submitted.

<input type="hidden" name="stars" value="5" id="stars-val" />

<script>
  function updateStarValue(starNum){ // star num is 1,2,3,4,5
  document.getElementByID("stars-val").val = starNum;
  }
</script>

Then on each of the stars, onclick=updateStarValue(2) etc.

Otherwise, use preg_replace to change the newline character to a

user5697101
  • 571
  • 4
  • 12