0

My document.getElementsByClassName('showmessage1').innerHTML is not working , here's the part of code . The alert and console functions are working properly . The only problem lies inside document.getElementsByClassName('showmessage1').innerHTML = ${res.data.message} this part

 const sendmessage =()=>{

const {name , email , message} = user

if(name&&email&&message)
{
    
   axios.post("http://localhost:9999/review" , user ).then( (res)=>{
   
       //console.log(`Response is ${res.data}  `)
       alert(res.data.message)
       document.getElementsByClassName('showmessage1').innerHTML = ` 
 ${res.data.message}`
 
     console.log("success!!");
     history.push('/')
   
  
    } )

   }else{
    //document.getElementById('showmessage').innerHTML = 'Invalid Input';
    document.getElementsByClassName('showmessage1').innerHTML = 'Invalid Input'
   }








  }




     <strike> 
     <form>

    <input type="text" name="name" value={user.name}   placeholder="Enter Your Name" 
     onChange = {handlechange} autoComplete="off"  />


    <input  type="text"    name="email" value={user.email}   placeholder="Enter Your. 
   Email Address"  onChange = {handlechange}/>

    <textarea type="text" name="message" value={user.message} placeholder="Enter Your 
      Message" style={{height:'200px'}} className="text" onChange = {handlechange} />



   
    </form>
  <p className="showmessage1"> </p>
   <div className="button" onClick = {sendmessage}  style={{backgroundColor:'#AA0000' 
    , borderColor:'#7C0A02' }}  > 
       Send
       </div>
      </strike>
  • Could you include your HTML code aswell? – newbNox Oct 06 '21 at 21:19
  • https://stackoverflow.com/a/17896758/4384238 (except ignore the jquery part) – DemiPixel Oct 06 '21 at 21:21
  • 1
    `getElementsByClassName` returns an array, not an element. you would have to loop through the elements and then set the innerHTML – Ramon de Vries Oct 06 '21 at 21:22
  • 1
    If want to call first class with specified name than use `document.getElementsByClassName(' ')[0]` and same for others like 2nd will have `[1]` so on – Rana Oct 06 '21 at 21:48
  • @RamondeVries it doesn't return an array, it returns an HTMLCollection, but you're right that it is an iterable and not an element. – pilchard Oct 06 '21 at 23:11

0 Answers0