Skip to main content

movieReviewsApp: How to get the value (actual written text) from an input into a variable and display it somewhere else?

I made a html/javaScript app that get movie data from an API and displays it (index.html), when someone click the "see details" link from any movieCard theyre redirected to a new page (singleMovieView.html). I want to be able to write in an input/textarea, click a button and then, with createdElemenst of div, paragraps, h, etc, upload it into an empty div I made specially just for the reviews.

The singleMovieView.html display info of the particular movie and then, below, there are two divs; one for writing the review (textArea/input and button)and below that another div to display the pastReviews.

Heres the code:

  • index.html:
<!DOCTYPE html>

<html>
  <head>
    <title>Movies Site</title>
    <link rel="stylesheet" href="style.css">
  </head>

  <body>
    <div class="topnav">
      <a class="active" href="#">Movies Site</a>

      <div class="search-container">
        <form role="search" id="form">
          <input type="search" id="query" name="q" placeholder="Search..">
        </form>
      </div>
    </div>

    <div style="padding-left:16px">

    <section id="section"></section>
  </body>

  <script src="script.js"></script>
</html>

  • script.js:
const APILINK = 'https://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&api_key=41ee980e4b5f05f6693fda00eb7c4fd4&page=1';
const IMG_PATH = "https://image.tmdb.org/t/p/w1280";
const SEARCHAPI = "https://api.themoviedb.org/3/search/movie?&api_key=41ee980e4b5f05f6693fda00eb7c4fd4&query=";


const main = document.getElementById("section");
const form = document.getElementById("form");
const search = document.getElementById("query");

const singleViewNameDiv = document.getElementById("movieNameSingleView");
returnMovies(APILINK)

function returnMovies(url)
{
  fetch(url).then(res => res.json()).then
  (function(data)
    {
      console.log(data.results);

      data.results.forEach
      (element =>
        {
          const div_card = document.createElement('div');
          div_card.setAttribute('class', 'card');

          const div_row = document.createElement('div');
          div_row.setAttribute('class', 'row');

          const div_column = document.createElement('div');
          div_column.setAttribute('class', 'column');

          const image = document.createElement('img');
          image.setAttribute('class', 'thumbnail');
          image.setAttribute('id', 'image');
          image.setAttribute('width', 250);

          const title = document.createElement('h3');
          title.setAttribute('id', 'title');

          const center = document.createElement('center');

          title.innerHTML = `${element.title}`;
          image.src = IMG_PATH + element.poster_path;

          let oneTitle = `${element.title}`;
          let twoImg = IMG_PATH + element.poster_path;
          let threeOverview = element.overview;
          let fourDate = element.release_date;

          //////////////////////////////////////////////////////////////////////////////////
          const aLink = document.createElement('a');
          aLink.setAttribute('href', 'singleViewMovie.html?oneTitle=' + oneTitle + '&twoImg=' + twoImg + '&threeOverview=' + threeOverview + '&fourDate=' + fourDate); //+ '&lastValue=#');
          aLink.innerText = 'Go to details';
          //////////////////////////////////////////////////////////////////////////////////

          center.appendChild(image);
          div_card.appendChild(center);
          div_card.appendChild(title);
          div_card.appendChild(aLink);
          div_column.appendChild(div_card);
          div_row.appendChild(div_column);

          main.appendChild(div_row);
        }
      );
    }
  );
}

form.addEventListener
("submit", (e) =>
  {
    e.preventDefault();
    main.innerHTML = '';

    const searchItem = search.value;

    if (searchItem)
    {
      returnMovies(SEARCHAPI + searchItem);
      search.value = "";
    }
  }
);
  • singleViewMovie:
<!DOCTYPE html>

<html>

  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>replitSingleMovieView</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
  </head>

  <body style="background-color: #131720;">
    <!--////////////////////"PRUEBA PARA VER CONTENIDO DE LOS PARAMETROS"////////////////////-->
    <div id ="forTests">
    </div>

    <!--////////////////////"TITULO PARA REGRESAR A INDEX.HTML"////////////////////-->
    <div>
      <a href="index.html">
        <h1>HOME</h1>
      </a>
    </div>

    <!--////////////////////"NOMBRE DE LA PELICULA"////////////////////-->
    <div id="movieNameSingleView">
      <!--
      <hr/>
      <h3 style="color: white">movieName</h3>
      <hr/>
      -->
    </div>

    <br/>

    <!--////////////////////"IMAGEN DE LA PELICULA"////////////////////-->
    <div id ="imageSingleView" style="background-color: #151f30; padding-left: 20px;">
      <!--
      <br/>
      <img width="550" src="spiderman.jpg" />
      <br/>
      <br/>
      -->
    </div>

    <br/>
    <br/>

    <!--////////////////////"DETALLES DE LA PELICULA CON EL NOMBRE, FECHA Y DESCRIPCION"////////////////////-->
    <div id="detailsSingleView">
      <!--
      <hr/>
        <h4 style="color: white">movieName</h4>
        <h6 style="color: white">releaseDate</h6>

        <p style="color: white">movieDescriptionOneTwoThreeFourFiveSixSevenEightNineTenElevenTwelveThirteen</p>
      <hr/>
      -->
    </div>

    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>

    <!--////////////////////"DIV PARA HACER REVIEWS"////////////////////-->
    <div>
      <h3 style="color: white">MAKE A REVIEW:</h3>

      <br/>

      <form id="newReviewsContent">  <!--<div id="newReviewsContent">-->
        <!--
        <input type="text" value="Username" id="userSpace">

        </br>
        </br>

        <textarea id="reviewSpace" rows="4" cols="50"></textarea>
        <textarea id="reviewBox" name="nameReviewBox" class="text" rows="4" cols="50"></textarea>
        -->

        <input type="text" placeholder="Review....." name="reviewBox" id="reviewBox"/>

        </br>

        <input type="submit" value="Add review"/>
      </form><!--</div>-->
    </div>

    <br/>
    <br/>

    <!--////////////////////"DIV MOSTRAR REVIEWS"////////////////////-->
    <div>
      <h3 style="color: white">PAST REVIEWS:</h3>

      </br>

      <div id="pastReviews">
      </div>
    </div>


    <script src="singleView.js"></script>
  </body>

  <script src="singleView.js"></script>
</html>
  • singleView.js:
let stringTitle = window.location.href;
let stringImage = window.location.href;
let stringOverview = window.location.href;
let stringDate = window.location.href;


let indexStartOne = stringTitle.indexOf('oneTitle=');
indexStartOne += 9;
let indexStartTwoForOne = stringTitle.indexOf('twoImg=');
indexStartTwoForOne -= 1;
//////////"VARIABLE QUE CONTIENE EL NOMBRE DEL TITULO"//////////
///////////////////////////////////////////////////////////////
let titleName = stringTitle.slice(indexStartOne, indexStartTwoForOne);


let indexStartTwo = stringImage.indexOf('twoImg=');
indexStartTwo += 7;
let indexStartThreeForTwo = stringImage.indexOf('threeOverview=');
indexStartThreeForTwo -= 1;
//////////"VARIABLE QUE CONTIENE LA URL DE LA IMAGEN"////////////
////////////////////////////////////////////////////////////////
let imageUrl = stringImage.slice(indexStartTwo, indexStartThreeForTwo);


let indexStartThree = stringOverview.indexOf('threeOverview=');
indexStartThree += 14;
let indexStartFourForThree = stringOverview.indexOf('fourDate=');
indexStartFourForThree -= 1;
//////////"VARIABLE QUE CONTIENE LA DESCRIPCION DE LA PELICULA"////////////
//////////////////////////////////////////////////////////////////////////
let descriptionDetails = stringOverview.slice(indexStartThree, indexStartFourForThree);

let indexStartFour = stringDate.indexOf('fourDate=');
indexStartFour += 9;
//////////"VARIABLE QUE CONTIENE LA FECHA DE LA PELICULA"////////////
////////////////////////////////////////////////////////////////////
let dateFormat = stringDate.slice(indexStartFour);



const singleViewTitleDiv = document.getElementById("movieNameSingleView");
const singleViewImageDiv = document.getElementById("imageSingleView");
const singleViewDescriptionDiv = document.getElementById("detailsSingleView");



const titleElement = document.createElement('h2');
const imageElement = document.createElement('img');
const overviewElement = document.createElement('p');
const dateElement = document.createElement('p');
const breakElement = document.createElement('br');



titleElement.innerHTML = "MOVIE: " + titleName;
titleElement.setAttribute('style', 'color: white');

imageElement.src = imageUrl;
imageElement.setAttribute('width', 600);

overviewElement.innerHTML = descriptionDetails;
overviewElement.setAttribute('style', 'color: white');

dateElement.innerHTML = "RELEASE DATE: " + dateFormat;
dateElement.setAttribute('style', 'color: white');



singleViewTitleDiv.appendChild(titleElement);
singleViewImageDiv.appendChild(imageElement);
singleViewDescriptionDiv.appendChild(dateElement);
singleViewDescriptionDiv.appendChild(breakElement);
singleViewDescriptionDiv.appendChild(overviewElement);

/*
http://127.0.0.1:3000/singleViewMovie.html?
oneTitle=
    Black%20Adam
&twoImg=
    https://image.tmdb.org/t/p/w1280/pFlaoHTZeyNkG83vxsAJiGzfSsa.jpg
&threeOverview=
    Nearly%205,000%20years%20after%20he%20was%20bestowed%20with%20the%20almighty%20powers%20of%20the%20Egyptian%20gods%E2%80%94and%20imprisoned%20just%20as%20quickly%E2%80%94Black%20Adam%20is%20freed%20from%20his%20earthly%20tomb,%20ready%20to%20unleash%20his%20unique%20form%20of%20justice%20on%20the%20modern%20world.
&fourDate=
    2022-10-19
*/

/////////////////////////////////////////////////////////
//////////"VARIABLES & FUNCIONES PARA REVIEWS"////////////
/////////////////////////////////////////////////////////


const numberReviews = 0;

const showReviews = document.getElementById("pastReviews");

const Form = document.getElementById("newReviewsContent");
const textArea = document.getElementById("reviewBox");

const button = document.querySelector('.button');

button.addEventListener
("click", (e) =>
  {
    e.preventDefault();

    numberReviews++;
    let reviewText = textArea.value;
    let headerText = "Review #" + numberReviews;
    let text = document.createElement('p');
    let header = document.createElement('h5');
    let newDiv = document.createElement('div');

    header.innerHTML = headerText;
    text.innerHTML = reviewText;

    newDiv.appendChild(header);
    newDiv.appendChild(text);
    showReviews.appendChild(newDiv);
  }
)



const divPastReviewSection = document.getElementById("pastReviews");
const newText = document.createElement('p');


newReview.addEventListener
('submit', e =>
  {
    e.preventDefault();

    const textReview = e.target.elements.content.vale;

    newText.innerHTML = textReview;
    divPastReviewSection.appendChild(newText);
  }
)

Via Active questions tagged javascript - Stack Overflow https://ift.tt/fEQJCwV

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data

ValueError: X has 10 features, but LinearRegression is expecting 1 features as input

So, I am trying to predict the model but its throwing error like it has 10 features but it expacts only 1. So I am confused can anyone help me with it? more importantly its not working for me when my friend runs it. It works perfectly fine dose anyone know the reason about it? cv = KFold(n_splits = 10) all_loss = [] for i in range(9): # 1st for loop over polynomial orders poly_order = i X_train = make_polynomial(x, poly_order) loss_at_order = [] # initiate a set to collect loss for CV for train_index, test_index in cv.split(X_train): print('TRAIN:', train_index, 'TEST:', test_index) X_train_cv, X_test_cv = X_train[train_index], X_test[test_index] t_train_cv, t_test_cv = t[train_index], t[test_index] reg.fit(X_train_cv, t_train_cv) loss_at_order.append(np.mean((t_test_cv - reg.predict(X_test_cv))**2)) # collect loss at fold all_loss.append(np.mean(loss_at_order)) # collect loss at order plt.plot(np.log(al...